The CSS outline property is pretty much similar to the border property. But the outline is drawn outside the element border. Here are some major differences which distinguish the outline property from border property.
- The outline does not occupy space from the box model, but the border does.
- The border is always in rectangular or square form but not outline.
- Unlike border, we do not have different outline styling for all side. The outline has to be same for all sides of an element.
Note: Internet Explorer6 and Netscape7 do not support outline property. In CSS we can use 4 properties to style or show the outline of an element.
- outline-width: It set the width of the outline.
- outline-style: It defines the different styling for the outline.
- outline-color: It specifies the outline colour.
- outline: It can specify all the above three properties in a single statement.
CSS outline-width Property
The outline-width property specifies the width for an element outline. And it accepts four values.
- thin (means 1px)
- medium (means 3px)
- thick (means 5px)
- Or we can simply use the length units in px, pt, cm, em etc.
Example
Preview:
Note: In the above preview you can see that the black outline is drawn outside the red border.
CSS outline-style property
The outline-style property is similar to the border-style property. It can specify the different type of styling to the outline structure. Here are the following values accepted by the outline-style:
- dotted: Set the dotted outline
- dashed: Set the dashed outline.
- solid: Set a single line solid outline
- double: Set two parallel lines outline.
- groove: Set a 3d groove outline
- ridge: Set a 3d ridged outline.
- inset: Set a 3D inset outline.
- outset: Set a 3D outset outline
- none: Set no outline
- hidden: Set a hidden outline
Example
Preview
CSS Outline-Color Property
Like other colour properties, it defines the colour for the element outline. It can accept value by color name, hex code, RGB code, etc.
Example
Preview
CSS outline Property
By far we have discussed different properties line outline-width, outline-color and outline-style to set the outline width, colour and style. But using the single outline property we can set all these three properties in a single statement.
Syntax
Example
Preview
CSS outline-offset Property
outline-offset is an outline property which is used to define the spacing between the element border and outline. And it accepts length values in px, cm, em etc.
Example
Preview
Summary
- The outline property in CSS is similar to the border.
- There are some differences which distinct outline from the border.
- It is not necessary that outline be always rectangular.
- For an element, the outline shape and size are similar to all sides.
- Like border-style, we have similar values for outline style.